package com.yunhui.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.yunhui.entity.RouteJb;
import com.yunhui.entity.Traveltype;
import com.yunhui.mapper.RouteJbMapper;
import com.yunhui.mapper.TraveltypeMapper;
import com.yunhui.service.TraveltypeService;

import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  旅游类型的业务处理的层实现类
 * </p>
 *
 * @author WGH
 * @since 2019-12-09
 */
@Service
public class TraveltypeServiceImpl  implements TraveltypeService{

    @Resource
    TraveltypeMapper traveltypeMapper;

    @Resource
    RouteJbMapper routeJbMapper;


    /**
     *查询
     * @param parentId 父级id
     * @return
     */

    @Override
    public List<Traveltype> getAppCategoryList(String parentId) {
        return traveltypeMapper.getAppCategoryList(parentId);
    }


    /**
     * 添加一级或者二级类型
     * @param traveltype
     * @return
     */
    @Override
    public Integer addTraveltype(Traveltype traveltype) {
        int num=0;
        try{
            num = traveltypeMapper.insert(traveltype);
        }catch (Exception e){
            e.printStackTrace();
        }
        return num;
    }

    @Override
    public List<Traveltype> getTpyeSonLsit() {
        List<Traveltype> list = null;
        try{
            list  = traveltypeMapper.getTpyeSonLsit();
        }catch (Exception e){
            e.printStackTrace();
        }
        return list;
    }

    @Override
    public Traveltype getTraveltypeByName(String name) {
        Traveltype traveltype = traveltypeMapper.selectOne(new QueryWrapper<Traveltype>().eq("typeName",name));
        return traveltype;
    }

    @Override
    public boolean delteTraveltypeById(Integer id) {
        int num = 0;
        try{
            num = traveltypeMapper.deleteById(id);
        }catch (Exception e){
            e.printStackTrace();
        }
        return num>0;
    }

    @Override
    public Integer selectRoutejbCountBySonid(String sonId) {
        int num = routeJbMapper.selectCount(new QueryWrapper<RouteJb>().eq("travelType2",sonId));
        return num;
    }
}
